import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import $ from "jquery"
import "./index.css"
class Index extends Component{
	submit(ev){
		let username=this.username.value
		let password=this.password.value
		if(username&&password){
			$.post("/loginsubmit",{
				"username":username,
				"password":password
			},function(data){
				if(data==="登录成功"){
					alert("欢迎你"+username+"回来")
					window.location="/"
					return ;
				}
				else
					alert(data)
				return ;
			})
		} 
		else
			ev.preventDefault()
	}
	render(){
		return (
			<div className="container ">
				<div className="fixedbg"></div>
				<div className="row">
					<div className="bg col-lg-4 col-md-4 col-sm-6 col-xs-6
									col-lg-push-4 col-md-push-4 col-sm-push-3 col-xs-push-3
					">
						<form>
							<div className="form-group">
								<label htmlFor="username" className="font-relief" >用户名</label>
								<input type="text" id="username" name="username" className="form-control" ref={(input)=>this.username=input}/>
							</div>
							<div className="form-group">
								<label htmlFor="password" className="font-relief" >密码</label>
								<input type="password" id="password" name="password" className="form-control" ref={(input)=>this.password=input}/>
							</div>
							<div className="form-group">
								<input 
									type="submit" 
									id="submit" 
									name="submit" 
									className="form-control submitmargin font-relief" 
									value="提交" 
									onClick={this.submit.bind(this)}
								/>
							</div>
						</form>
						
					</div>
				</div>
			</div>
		)
			
	}
}
ReactDOM.render(<Index />, document.getElementById('index'));
